/*
 * Copyright (c) 2001, 2002 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 */
package net.sourceforge.perforce.api.internal;

import net.sourceforge.perforce.api.IError;
import net.sourceforge.perforce.api.Policy;

/**
  * Wrapper class for Perforce API Error class.
  * 
  * @version $Revision: 41 $
  * @author  <a href="mailto:bpruessmann@users.sourceforge.net>Boris Pruessmann</a>
  */
public final class Error implements IError
{
	// --------------------------------------------------------------------------- Private Variables
	
	/** Used to store the native reference.
	  * <br>DON'T TOUCH THE CONTENT OF THIS VARIABLE 
	  */
	private int _nativeHandle;
	
	// ------------------------------------------------------------------------- Public Constructors
	
	/** Constructor for Error. */
	public Error()
	{
		construct();
	}
	
	// ------------------------------------------------------------------------------ Public Methods

	/** Disposes the Error object, freeing native resources. */
	public void dispose()
	{
		destruct();
	}
		
	/** @see IError#clear() */
	public native void clear();
	
	/** @see IError#test() */	
	public native boolean test();

	/** @see IError#isWarning() */
	public native boolean isInfo();

	/** @see IError#isWarning() */
	public native boolean isWarning();

	/** @see IError#isFatal() */	
	public native boolean isFatal();

	/** @see IError#isError() */	
	public native boolean isError();

	/** @see IError#getSeverity() */
	public native int getSeverity();
	
	/** @see IError#getGeneric() */	
	public native int getGeneric();

	/** @see IError#formatSeverity() */
	public native String formatSeverity();
		
	/** @see IError#format(int) */
	public native String format(int options);
	
	/** @see Object#toString() */
	public String toString()
	{
		Object[] values = new Object[] 
		{ 
			new Integer(getSeverity()),
			new Integer(getGeneric()),
			format(IError.EF_PLAIN),
		};
					
		return Policy.bind("Error.toString", values);                                  //$NON-NLS-1$
	}

	// ----------------------------------------------------------------------------- Private Methods

	/**
	  * Call this method to create the native Error object.
	  */
	private native void construct();
	
	/**
	  * Call this method to destroy the native Error object.
	  */
	private native void destruct();
	
}

